//package com.pengzy.core.gateway_security;
//
//import com.pengzy.comment.core.jwt.JwtTokenUtils;
//import com.pengzy.comment.web.result.JsonResult;
//import com.pengzy.comment.web.webFluxUtils.ResponseResult;
//import com.pengzy.supports.dto.LoginUser;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.web.server.WebFilterExchange;
//import org.springframework.security.web.server.authentication.WebFilterChainServerAuthenticationSuccessHandler;
//import org.springframework.stereotype.Component;
//import reactor.core.publisher.Mono;
//
//import java.time.Duration;
//import java.time.LocalDateTime;
//import java.time.temporal.ChronoUnit;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.stream.Collectors;
//
///**
// * @author xiaozhi 2023/7/18
// */
//
//@Component
//public class AuthenticationSuccessConfig extends WebFilterChainServerAuthenticationSuccessHandler {
//
//
//    @Override
//    public Mono<Void> onAuthenticationSuccess(WebFilterExchange webFilterExchange, Authentication authentication) {
//        User user = (User) authentication.getPrincipal();
//        HashMap<String, Object> info = new HashMap<>();
//        info.put("user", user.getUsername());
//        String role_ = user.getAuthorities().toString();
//        info.put("roles", role_);
//        LocalDateTime dateTime = LocalDateTime.now().plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS);
//        int expire = (int) Duration.between(dateTime, LocalDateTime.now()).toMinutes() * 60;
//        String token = JwtTokenUtils.createToken(info, expire); //token 1天后的零点过期
//        Map<String, String> responseMap = new HashMap<>();
//        responseMap.put("code", "success");
//        responseMap.put("token", token);
//        responseMap.put("permisser", role_);
//        LoginUser loginUser=new LoginUser();
//        loginUser.setUsername(user.getUsername());
//        loginUser.setToken(token);
//        loginUser.setPermissions(user.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList()));
//        loginUser.setRoles(role_);
//        return ResponseResult.writeWith(webFilterExchange.getExchange(), JsonResult.success(loginUser));
//    }
//}
